package com.example.myapplication;

import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;
import android.util.Log;


public class Fragment1_Page5ActivityMusicService extends Service {

    private MediaPlayer mediaPlayer;

    public Fragment1_Page5ActivityMusicService() {
        Log.d("tjk","myservice start");
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        mediaPlayer=MediaPlayer.create(this,R.raw.her_dream);// 使用MediaPlayer.create方法创建MediaPlayer对象，并传入上下文和音频资源ID
        mediaPlayer.start();
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
        throw new UnsupportedOperationException("Not yet implemented");
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.d("tjk","myservice destroy");
        mediaPlayer.stop();
    }
}